package com.prs.crm.dao.crm.impl;

import java.sql.SQLException;
import java.util.List;

import org.hibernate.Criteria;
import org.hibernate.HibernateException;
import org.hibernate.Session;
import org.hibernate.criterion.Restrictions;
import org.springframework.orm.hibernate3.HibernateCallback;

import com.prs.crm.dao.crm.mainBillDao;
import com.prs.crm.dao.impl.BaseDaoImpl;
import com.prs.crm.domain.crm.Dispatch;
import com.prs.crm.domain.crm.mainBill;

public class mainBillDaoImpl extends BaseDaoImpl<mainBill> implements
		mainBillDao {

	@SuppressWarnings("unchecked")
	@Override
	public mainBill getmainBill(final String na) {
		return (mainBill) this.getHibernateTemplate().execute(
				new HibernateCallback(){
					@Override
					public Object doInHibernate(Session arg0)
							throws HibernateException, SQLException {
						Criteria criteria = arg0.createCriteria(mainBill.class);
						criteria.add(Restrictions.eq("billNum", na));
						if(criteria.list().size()==0){
						return null;	
						}else{
						return criteria.list().get(0);
						}
					}
					
				}
			);
	}

	@Override
	public void updatebill(mainBill s) {
		this.getHibernateTemplate().saveOrUpdate(s);
		
	}

}
